package Yang.homework3;

import java.util.*;

public class WorkerTest {
    private String name;
    private int age;
    private double salary;

    public WorkerTest() {
    }

    public WorkerTest(String name, int age, double salary) {
        setName(name);
        setAge(age);
        setSalary(salary);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

/*    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        WorkerTest that = (WorkerTest) o;
        return age == that.age &&
                Double.compare(that.salary, salary) == 0 &&
                Objects.equals(name, that.name);
    }*/

    @Override
    public int hashCode() {
        return Objects.hash(name, age, salary);
    }

    @Override
    public String toString() {
        return "WorkerTest{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                '}';
    }

    //为Worker类重写equals 方法，当姓名、年龄、工资全部相等时候才返回true
    @Override
    public boolean equals(Object o) {
        if (null == o) return false;
        if (this == o) return true;
        if (o instanceof WorkerTest) {
            return this.getName().equals(((WorkerTest) o).getName()) &&
                    this.getAge() == ((WorkerTest) o).getAge() &&
                    this.getSalary() == ((WorkerTest) o).getSalary();

        }
        return false;
    }




    //自定义成员方法打印
    public void work(String name){
        System.out.println(getName() + "正在工作");
    }
    public String message(){
        return getName() + " " + getAge() + " " + getSalary();
    }

    public static void main(String[] args) {
        //定义List集合，在List集合中增加三个员工，基本信息如下：
        // "凤姐" 18 20000  "欧阳峰" 60 8000  "刘德华" 40 30000
        List lt1 = new ArrayList();
        WorkerTest w1 = new WorkerTest("凤姐", 18, 20000);
        lt1.add(Arrays.asList(w1.message()));

        WorkerTest w2 = new WorkerTest("欧阳峰", 60, 8000);
        lt1.add(Arrays.asList(w2.message()));

        WorkerTest w3 = new WorkerTest("刘德华", 40, 30000);
        lt1.add(Arrays.asList(w3.message()));
        System.out.println("员工信息为：" + lt1);

        //在"欧阳峰"之前插入一个员工，信息为：姓名："张柏芝"，年龄：35，工资3300
        WorkerTest w4 = new WorkerTest("张柏芝", 35, 3300);
        lt1.add(1,Arrays.asList(w4.message()));
        System.out.println("添加员工后的信息为：" + lt1);

        //删除"刘德华"的信息
        lt1.remove(3);
        System.out.println("删除后的信息为：" + lt1);

        //利用for 循环遍历，打印List 中所有员工的信息
        for (int i = 0; i<lt1.size(); i++){
            Object o = lt1.get(i);
            System.out.println("第" + (i+1) + "个员工的信息为：" + o);
        }


        //测试重写equals方法
        System.out.println("-------------------------------");
        WorkerTest w5 = new WorkerTest("张柏芝", 35, 3300);
        WorkerTest w6 = new WorkerTest("张柏芝", 36, 3300);
        System.out.println(w2.equals(w1));
        System.out.println(w4.equals(w5));
        System.out.println(w6.equals(w5));
}
















/*        WorkerTest w1 = new WorkerTest("凤姐", 18, 20000);
        List lt1 = new ArrayList();
        lt1.addAll(Arrays.asList(w1.getName() + " " + w1.getAge() + " " + w1.getSalary()));
        System.out.println(lt1);*/

/*        List lt1 = new ArrayList();
        lt1.addAll(Arrays.asList("凤姐",18,20000,"欧阳峰",60,8000,"刘德华",40,30000));
        System.out.println("lt1" + lt1);

        //在"欧阳峰"之前插入一个员工，信息为：姓名："张柏芝"，年龄：35，工资3300
        lt1.addAll(3,Arrays.asList("张柏芝",35,3300));
        System.out.println("lt1" + lt1);*/

        //删除"刘德华"的信息



    }





